package ability139

import (
    "log"
    "errors"
    "topsdk"
    "topsdk/ability139/request"
    "topsdk/ability139/response"
    "topsdk/util"
)

type Ability139 struct {
    Client *topsdk.TopClient
}

func NewAbility139(client *topsdk.TopClient) *Ability139{
    return &Ability139{client}
}

/*
    用户开放信息获取
*/
func (ability *Ability139) TaobaoMiniappUserInfoGet(req *request.TaobaoMiniappUserInfoGetRequest,session string) (*response.TaobaoMiniappUserInfoGetResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability139 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.miniapp.userInfo.get",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoMiniappUserInfoGetResponse{}
    if(err != nil){
        log.Println("taobaoMiniappUserInfoGet error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    获取授权session信息
*/
func (ability *Ability139) TaobaoOpenlinkSessionGet(req *request.TaobaoOpenlinkSessionGetRequest) (*response.TaobaoOpenlinkSessionGetResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability139 topClient is nil")
    }
    var jsonStr,err = ability.Client.Execute("taobao.openlink.session.get",req.ToMap(),req.ToFileMap())
    var respStruct = response.TaobaoOpenlinkSessionGetResponse{}
    if(err != nil){
        log.Println("taobaoOpenlinkSessionGet error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
